<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>login</title>
    <script src="js/jquery.js"></script>
</head>
<body>
<div>
    <div>
        邮箱: <input type="text" name="email"/><br/>
        密码: <input type="password" name="password"/><br/>
        <a href="register.html">注册新用户</a><br/>
        <button id="login_submit" type="submit">登录</button>
    </div>
</div>

<script>
    $(document).on('click', '#login_submit', function () {
        email = $("input[name='email']").val();
        password = $("input[name='password']").val();
        if (email.length < 1) {
            alert("请先输入邮箱");
            return
        }
        if (password.length < 1) {
            alert("请先输入密码");
            return
        }
        $.ajax({
            type: "get",
            url: "/api/user/login/" + email + "/" + password,
            error: function () {
                alert("用户名或密码错误");
            },
            success: function (data) {

                if (data.length > 0) {
                    window.location.href = "/welcome.html"
                } else {
                    alert("用户名或密码错误");
                }
            }

        })
    });

</script>
</body>
</html>